#include "proteinrendercontrol.h"
#include "proteinrenderer.h"
#include "../../data/proteindata.h"

using namespace PBVP;

ProteinRenderControl::ProteinRenderControl(ProteinRenderer *pRenderer, QWidget *parent)
	: QWidget(parent)
{
	ligandVec.push_back(false);
	ui.setupUi(this);
	m_pRenderer = pRenderer;
	if(m_pRenderer->m_ShowProtein) {
		ui.showProtein->setChecked(true);
		if(m_pRenderer->m_ShowAtoms) ui.showAtoms->setChecked(true);
		if(m_pRenderer->m_ShowBackbone) ui.showBackbone->setChecked(true);
	}
	ui.showRibbons->setCheckable(false);
	
	connect(ui.showProtein, SIGNAL(stateChanged(int)), m_pRenderer, SLOT(setShowProtein(int)));
	connect(ui.showAtoms, SIGNAL(stateChanged(int)), m_pRenderer, SLOT(setShowAtoms(int)));
	connect(ui.showBackbone, SIGNAL(stateChanged(int)), m_pRenderer, SLOT(setShowBackbone(int)));
	connect(ui.showBBox, SIGNAL(stateChanged(int)), m_pRenderer, SLOT(setShowBBox(int)));

	connect(ui.showLigandAtoms, SIGNAL(stateChanged(int)), this, SLOT(toggleLigandShow(int)));
	connect(ui.ligandSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(changeSelectedLigand(int)));
}

ProteinRenderControl::~ProteinRenderControl()
{

}

/********************************************************************************/
/* slots																		*/
/********************************************************************************/
void ProteinRenderControl::toggleLigandShow(int state)
{
	int id = ui.ligandSelect->currentIndex();
	if(id < 0) return;
	switch(state) {
	case Qt::Checked:
		ligandVec[id] = true;
		break;
	case Qt::Unchecked:
		ligandVec[id] = false;
		break;
	}
}

void ProteinRenderControl::changeSelectedLigand(int id)
{
	if(id < 0) return;
	bool show = ligandVec[id];
	ui.showLigandAtoms->setChecked(show);
	m_pRenderer->updateView();
}
